set(CPACK_GENERATOR "RPM")
set(CPACK_PACKAGE_NAME "nemu")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "nEMU - ncurses interface for QEMU")
set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/DESCRIPTION")
set(CPACK_PACKAGING_INSTALL_PREFIX /usr)
set(CPACK_PACKAGE_VERSION ${GIT_TAG_VERSION})
set(CPACK_PACKAGE_FILE_NAME
    "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}.${CMAKE_SYSTEM_PROCESSOR}")
set(CPACK_RPM_SPEC_MORE_DEFINE "${CPACK_RPM_SPEC_MORE_DEFINE}
%global __strip /bin/true
%define _build_pkgcheck_set %{nil}
%define _build_pkgcheck_srpm %{nil}
%define ___build_shell /usr/bin/env DONT_COMPRESS=1 /bin/sh
")

if(CPACK_RPM_PACKAGE_SOURCES)
  set(CPACK_RPM_SOURCE_PKG_BUILD_PARAMS "")
  set(CPACK_RPM_SOURCE_PKG_BUILD_PARAMS
      "${CPACK_RPM_SOURCE_PKG_BUILD_PARAMS} -DCMAKE_INSTALL_PREFIX=${CPACK_PACKAGING_INSTALL_PREFIX}"
  )
  set(CPACK_RPM_SOURCE_PKG_BUILD_PARAMS
      "${CPACK_RPM_SOURCE_PKG_BUILD_PARAMS} -DCMAKE_INSTALL_PREFIX=${CPACK_PACKAGING_INSTALL_PREFIX}"
  )
  set(CPACK_RPM_SOURCE_PKG_BUILD_PARAMS
      "${CPACK_RPM_SOURCE_PKG_BUILD_PARAMS} -DGIT_TAG_VERSION=${GIT_TAG_VERSION}"
  )
  set(CPACK_RPM_SOURCE_PKG_BUILD_PARAMS
      "${CPACK_RPM_SOURCE_PKG_BUILD_PARAMS} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
  )
  set(CPACK_RPM_SOURCE_PKG_BUILD_PARAMS
      "${CPACK_RPM_SOURCE_PKG_BUILD_PARAMS} -DNM_CUSTOM_SYS_INCLUDE=${NM_CUSTOM_SYS_INCLUDE}"
  )
  set(CPACK_RPM_SOURCE_PKG_BUILD_PARAMS
      "${CPACK_RPM_SOURCE_PKG_BUILD_PARAMS} -DNM_WITH_OVF_SUPPORT=${NM_WITH_OVF_SUPPORT}"
  )
  set(CPACK_RPM_SOURCE_PKG_BUILD_PARAMS
      "${CPACK_RPM_SOURCE_PKG_BUILD_PARAMS} -DNM_WITH_VNC_CLIENT=${NM_WITH_VNC_CLIENT}"
  )
  set(CPACK_RPM_SOURCE_PKG_BUILD_PARAMS
      "${CPACK_RPM_SOURCE_PKG_BUILD_PARAMS} -DNM_WITH_SPICE=${NM_WITH_SPICE}")
  set(CPACK_RPM_SOURCE_PKG_BUILD_PARAMS
      "${CPACK_RPM_SOURCE_PKG_BUILD_PARAMS} -DNM_WITH_NETWORK_MAP=${NM_WITH_NETWORK_MAP}"
  )
  set(CPACK_RPM_SOURCE_PKG_BUILD_PARAMS
      "${CPACK_RPM_SOURCE_PKG_BUILD_PARAMS} -DNM_WITH_DBUS=${NM_WITH_DBUS}")
  set(CPACK_RPM_SOURCE_PKG_BUILD_PARAMS
      "${CPACK_RPM_SOURCE_PKG_BUILD_PARAMS} -DNM_WITH_QEMU=${NM_WITH_QEMU}")
  set(CPACK_RPM_SOURCE_PKG_BUILD_PARAMS
      "${CPACK_RPM_SOURCE_PKG_BUILD_PARAMS} -DNM_QEMU_TARGET_LIST=${NM_QEMU_TARGET_LIST}"
  )
  set(CPACK_RPM_SOURCE_PKG_BUILD_PARAMS
      "${CPACK_RPM_SOURCE_PKG_BUILD_PARAMS} -DNM_WITH_NCURSES=${NM_WITH_NCURSES}")
  set(CPACK_RPM_SOURCE_PKG_BUILD_PARAMS
    "${CPACK_RPM_SOURCE_PKG_BUILD_PARAMS} -DNM_WITH_USB=${NM_WITH_USB}")

elseif(NM_WITH_QEMU)
  set(CPACK_RPM_PACKAGE_REQUIRES "bzip2")
  set(CPACK_RPM_PACKAGE_REQUIRES "${CPACK_RPM_PACKAGE_REQUIRES}, libseccomp ")
  set(CPACK_RPM_PACKAGE_REQUIRES "${CPACK_RPM_PACKAGE_REQUIRES}, libjpeg ")
  set(CPACK_RPM_PACKAGE_REQUIRES "${CPACK_RPM_PACKAGE_REQUIRES}, libpng ")
  set(CPACK_RPM_PACKAGE_REQUIRES "${CPACK_RPM_PACKAGE_REQUIRES}, libcap-ng ")
  set(CPACK_RPM_PACKAGE_REQUIRES "${CPACK_RPM_PACKAGE_REQUIRES}, libcurl ")
  set(CPACK_RPM_PACKAGE_REQUIRES "${CPACK_RPM_PACKAGE_REQUIRES}, glib2 ")
  set(CPACK_RPM_PACKAGE_REQUIRES "${CPACK_RPM_PACKAGE_REQUIRES}, pixman ")
  set(CPACK_RPM_PACKAGE_REQUIRES "${CPACK_RPM_PACKAGE_REQUIRES}, libaio ")
  set(CPACK_RPM_PACKAGE_REQUIRES "${CPACK_RPM_PACKAGE_REQUIRES}, spice-server ")
  set(CPACK_RPM_PACKAGE_REQUIRES "${CPACK_RPM_PACKAGE_REQUIRES}, usbredir ")
  set(CPACK_RPM_PACKAGE_REQUIRES "${CPACK_RPM_PACKAGE_REQUIRES}, libcap ")
  set(CPACK_RPM_PACKAGE_REQUIRES "${CPACK_RPM_PACKAGE_REQUIRES}, libattr ")
endif()

set(CPACK_RPM_PACKAGE_LICENSE "BSD-2-clause")
set(CPACK_RPM_PACKAGE_GROUP "Applications/Emulators")
set(CPACK_RPM_PACKAGE_URL "https://github.com/nemuTUI/nemu")
set(CPACK_RPM_PACKAGE_VENDOR "Boris Stepanenko <boris.stepanenko@gmail.com>")
set(CPACK_RPM_PACKAGE_AUTOREQ 1)
set(CPACK_RPM_POST_INSTALL_SCRIPT_FILE
    "${CMAKE_CURRENT_SOURCE_DIR}/postinstall.sh")
set(CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE
    "${CMAKE_CURRENT_SOURCE_DIR}/postuninstall.sh")

list(APPEND CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION
            "/usr/share/locale")
list(APPEND CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION
            "/usr/share/locale/ru")
list(APPEND CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION
            "/usr/share/locale/ru/LC_MESSAGES")
list(APPEND CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION
            "/usr/share/bash-completion")
list(APPEND CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION
            "/usr/share/bash-completion/completions")
list(APPEND CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION
            "/usr/share/bash-completion/completions/nemu")
list(APPEND CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION
            "/usr/share/man")
list(APPEND CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION
            "/usr/share/man/man1")

include(CPack)
